//
//  ZLRightCalender.m
//  项目三
//
//  Created by rimi on 15/10/15.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "ZLRightCalender.h"
#import "ZLCalenderCell.h"
#import "Tool.h"

@interface ZLRightCalender ()

@end

@implementation ZLRightCalender

static NSString * const cellIdentifier = @"daycell";
static NSString * const headerIdentifier = @"headView";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Register cell classes
    [self.collectionView registerClass:[ZLCalenderCell class] forCellWithReuseIdentifier:cellIdentifier];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete method implementation -- Return the number of sections
    return 0;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete method implementation -- Return the number of items in the section
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ZLCalenderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    
    if (indexPath.row < _firstWeekdayInWeek - 1) {
        
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
        
    } else {
        
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
        cell.day.text = [NSString stringWithFormat:@"%u", indexPath.row - _firstWeekdayInWeek + 2];
    }
    
    if (indexPath.row > _days + _firstWeekdayInWeek - 2) {
        cell.day.text = @"";
        
        CGRect frame = collectionView.frame;
        NSUInteger row = collectionView.visibleCells.count % 7 != 0 ? collectionView.visibleCells.count / 7 + 2 : collectionView.visibleCells.count / 7 + 1;
        frame.size.height = __cellSide * row;
        collectionView.frame = frame;
        
//        CGRect tableViewFrame = _tableview.frame;
//        tableViewFrame.origin.y = CGRectGetMaxY(frame);
//        tableViewFrame.origin.x = CGRectGetMinX(frame);
//        tableViewFrame.size.height = self.bottonImage.frame.origin.y - tableViewFrame.origin.y - 10;
//        _tableview.frame = tableViewFrame;
    }
    cell.layer.borderColor = [UIColor grayColor].CGColor;
    cell.layer.borderWidth = 1.3;
    return cell;
    
    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
